<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
         contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp" %>

<s:action name="coupon!view" var="view" executeResult="false"/>


<head>
    <title>优惠券发放</title>
</head>
<body>
<div id="wrapper">
    <c:set var="left">coupon</c:set>
    <%@ include file="/include/left/operation.jsp" %>

    <s:action name="user!search" var="userList" executeResult="false">
        <s:param name="query.enabled">true</s:param>
        <s:param name="query.order">addTime</s:param>
        <s:param name="query.desc">true</s:param>
    </s:action>

    <div id="page-wrapper" class="gray-bg">

        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>优惠券管理</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="${ctx}/coupon/">优惠券管理</a>
                    </li>
                    <li>
                        <a>优惠券管理</a>
                    </li>
                    <li class="active">
                        <strong>优惠券发放</strong>
                    </li>
                </ol>
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight ecommerce">
            <form action="${ctx}/coupon/send" method="get" class="shaix">
                <div class="ibox-content m-b-sm border-bottom">

                    <input type="hidden"  name="id" value="${view.coupon.id}">

                    <div class="row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="title">优惠券标题</label>
                                <input type="text" id="title" value="${view.coupon.title}" readonly
                                       placeholder="请输入优惠券标题"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="username">账号</label>
                                <input type="text" id="username" name="query.username" value="${query.username}"
                                       placeholder="请输入账号"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="pagesize">每页显示条数</label>
                                <input type="text" id="pagesize" name="query.pagesize" value="${query.pagesize}"
                                       placeholder="请输入每页显示条数"
                                       class="form-control">
                            </div>
                        </div>

                        <div class="col-sm-12">
                            <input type="submit" class="btn btn-sm btn-primary" value="查询"/>
                        </div>
                    </div>

                </div>
            </form>


            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox">
                        <div class="ibox-content">

                            <table class="footable table table-striped table-hover toggle-arrow-tiny default breakpoint footable-loaded"
                                   data-page-size="15">
                                <thead>
                                <td colspan="5"><input type="checkbox" id="checkAll" onclick="checkChange(this)"> 全选&nbsp;&nbsp;&nbsp;
                                    <a class="btn btn-success btn-xs mr30" href="javascript:void(0);"
                                       onclick="plSend('您确定要分配吗?');">批量分配优惠券(${view.coupon.title})</a>
                                </td>
                                <tr>
                                    <th data-hide="all"></th>
                                    <th data-toggle="true" class="footable-visible footable-first-column footable-sortable">账号<span class="footable-sort-indicator"></span></th>
                                    <th data-hide="phone" class="footable-visible footable-sortable">昵称<span class="footable-sort-indicator"></span></th>
                                    <th data-hide="all" class="footable-sortable">注册时间<span class="footable-sort-indicator"></span></th>
                                </tr>
                                </thead>
                                <tbody>

                                <s:iterator value="%{#userList.users}" status="rowStatus" var="user">
                                    <c:if test="${id!=1}">
                                        <tr class="footable-even">
                                            <td class="footable-visible">
                                                <input type="checkbox" id="user${id}" name="ids" value="${id}">
                                            </td>
                                            <td class="footable-visible">${username}</td>

                                            <td class="footable-visible">
                                                <c:if test="${user.photo==null || empty user.photo}">
                                                    暂无图片
                                                </c:if>
                                                <c:if test="${user.photo!=null && !empty user.photo}">
                                                    <img src="${user.photo}!icon.jpg" width="25" height="25">
                                                </c:if>
                                                    ${user.nickname}
                                            </td>
                                            <td class="footable-visible"><s:date name="%{addTime}" format="yyyy-MM-dd HH:mm"></s:date></td>
                                        </tr>
                                    </c:if>
                                </s:iterator>
                                </tbody>


                            </table>
                            <c:set var="href">id=${view.coupon.id}&query.pagesize=${query.pagesize}&</c:set>
                            <%@ include file="/common/page.jsp" %>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <%@ include file="/common/footer.jsp" %>

    </div>

</div>

<%@ include file="/common/scripts.jsp" %>

<script type="text/javascript">
    //    全选
    function checkChange(obj) {
        $("input[type='checkbox']").prop('checked', $(obj).prop('checked'));
    }

    //    批量审核
    function plSend(msg) {
        var _ids = "";
        $("input[name=ids]").each(function () {
            if ($(this).is(":checked")) {
                _ids += $(this).val() + ',';
            }
        });
        $.ajax({
            url: "${ctx}/coupon!distribution.action",
            type: "post",
            async: false,  //同步
            data: {
                id: '${view.coupon.id}',
                userIds: _ids
            },
            dataType: "json",
            success: function (result) {
                if(result.status==1){
                    window.location.href='${ctx}/coupon/';
                }else {
                    layer.msg(result.msg);
                }
            }
        });

    }

</script>

</body>

